package com.qifenqian.turbot.module.adapter.marketing

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.qifenqian.turbot.R
import kotlinx.android.synthetic.main.item_free_time_discount_child.view.*

/**
 * @author H
 * @createTime 2018/12/24 19:08
 * @description 用户评论中的图片适配器
 * @see
 * @since
 */
class FreeTimeDiscountChildAdapter(context: Context, list: MutableList<String>) : RecyclerView.Adapter<FreeTimeDiscountChildAdapter.ImageViewHolder>() {

    private var mContext: Context? = null
    private var mList: MutableList<String> = mutableListOf()

    init {
        mContext = context
        mList = list
    }

    override fun onCreateViewHolder(parent: ViewGroup, p1: Int): ImageViewHolder {
        val view = LayoutInflater.from(mContext).inflate(R.layout.item_free_time_discount_child, parent, false)
        return ImageViewHolder(view)
    }

    override fun getItemCount(): Int {
        return mList.size
    }

    override fun onBindViewHolder(holder: ImageViewHolder, i: Int) {
        holder.itemView.tv_item_child_free_time_discount_discount.text = mList[i]
        holder.itemView.tv_item_child_free_time_discount_time.text = mList[i]
        holder.itemView.setOnClickListener {
            if (mOnFreeTimeDiscountClickListener != null) {
                mOnFreeTimeDiscountClickListener!!.onClick(i, holder.itemView)
            }
        }
    }

    fun remove(position: Int) {
        mList.removeAt(position)
        notifyItemRemoved(position)
    }

    class ImageViewHolder(view: View) : RecyclerView.ViewHolder(view)

    fun setOnFreeTimeDiscountClickListener(onFreeTimeDiscountClickListener: OnFreeTimeDiscountClickListener) {
        mOnFreeTimeDiscountClickListener = onFreeTimeDiscountClickListener
    }

    private var mOnFreeTimeDiscountClickListener: OnFreeTimeDiscountClickListener? = null

    interface OnFreeTimeDiscountClickListener {
        fun onClick(position: Int, view: View)
    }
}
